b6356e8315944b42c5deb48d1a28a6e171966805,assertions-examples/src/test/java/org/assertj/examples/PathAssertionsExamples.java,PathAssertionsExamples,path_assertions,#,156

Before Change


	assertThat(existingFile).hasFileName("somefile.txt");
	assertThat(symlinkToExistingFile).hasFileName("symlink-to-somefile.txt");

	if (SystemUtils.IS_OS_UNIX) {
	  assertThat(Paths.get("/foo/bar")).isAbsolute();
	  assertThat(Paths.get("foo/bar")).isRelative();
	  assertThat(Paths.get("/usr/lib")).isNormalized();
	  assertThat(Paths.get("a/b/c")).isNormalized();
	  assertThat(Paths.get("../d")).isNormalized();
	  assertThat(Paths.get("/")).hasNoParent();
	  assertThat(Paths.get("foo")).hasNoParentRaw();
	  assertThat(Paths.get("/usr/lib")).startsWith(Paths.get("/usr"))

After Change



  @Test
  public void path_assertions() throws Exception {
	assumeTrue(SystemUtils.IS_OS_UNIX);

	// Create a regular file, and a symbolic link pointing to it
	final Path existingFile = Paths.get("somefile.txt");
	write(existingFile, "foo".getBytes());
	final Path symlinkToExistingFile = Paths.get("symlink-to-somefile.txt");
	deleteIfExists(symlinkToExistingFile);
	createSymbolicLink(symlinkToExistingFile, existingFile);

	// Create a symbolic link whose target does not exist
	final Path nonExistentPath = Paths.get("nonexistent");
	final Path symlinkToNonExistentPath = Paths.get("symlinkToNonExistentPath");
	deleteIfExists(symlinkToNonExistentPath);
	createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);

	// create directory and symlink to it
	Path dir = Paths.get("target/dir");
	deleteIfExists(dir);
	createDirectory(dir);
	final Path dirSymlink = Paths.get("target", "dirSymlink");
	deleteIfExists(dirSymlink);
	createSymbolicLink(dirSymlink, dir.toAbsolutePath());

	// assertions examples

	assertThat(existingFile).exists();
	assertThat(symlinkToExistingFile).exists();
	assertThat(existingFile).existsNoFollowLinks();
	assertThat(symlinkToNonExistentPath).existsNoFollowLinks();

	assertThat(nonExistentPath).doesNotExist();

	assertThat(existingFile).isRegularFile();
	assertThat(symlinkToExistingFile).isRegularFile();

	assertThat(symlinkToExistingFile).isSymbolicLink();
	assertThat(dirSymlink).isDirectory().isSymbolicLink();
	assertThat(symlinkToNonExistentPath).isSymbolicLink();

	assertThat(dir).isDirectory();
	assertThat(dirSymlink).isDirectory();
	assertThat(dir).hasParent(Paths.get("target"))
	               .hasParent(Paths.get("target/dir/..")) // would fail with hasParentRaw
	               .hasParentRaw(Paths.get("target"));

	assertThat(existingFile.toRealPath()).isCanonical();

	assertThat(existingFile).hasFileName("somefile.txt");
	assertThat(symlinkToExistingFile).hasFileName("symlink-to-somefile.txt");

	assertThat(Paths.get("/foo/bar")).isAbsolute();
	assertThat(Paths.get("foo/bar")).isRelative();
	assertThat(Paths.get("/usr/lib")).isNormalized();
	assertThat(Paths.get("a/b/c")).isNormalized();
	assertThat(Paths.get("../d")).isNormalized();
	assertThat(Paths.get("/")).hasNoParent();
	assertThat(Paths.get("foo")).hasNoParentRaw();
	assertThat(Paths.get("/usr/lib")).startsWith(Paths.get("/usr"))